package com.heze.xunhuan.controller;

import com.heze.xunhuan.service.UserService;
import com.heze.xunhuan.utils.SecurityContextUtil;
import com.heze.xunhuan.vo.Result;
import com.heze.xunhuan.vo.UserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 *
 * @author heze-xunhuan
 */
@Tag(name = "用户管理", description = "用户信息管理相关接口")
@RestController
@RequestMapping("/api/v1/users")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @Operation(summary = "获取用户信息", description = "获取当前登录用户的信息")
    @GetMapping("/profile")
    public Result<UserVO> getProfile() {
        Long userId = SecurityContextUtil.getCurrentUserId();
        if (userId == null) {
            return Result.unauthorized("未登录");
        }
        UserVO userVO = userService.getUserInfo(userId);
        return Result.success(userVO);
    }

    @Operation(summary = "更新用户信息", description = "更新当前登录用户的信息")
    @PutMapping("/profile")
    public Result<Void> updateProfile(@RequestBody UserVO userVO) {
        Long userId = SecurityContextUtil.getCurrentUserId();
        if (userId == null) {
            return Result.unauthorized("未登录");
        }
        userService.updateUserInfo(userId, userVO);
        return Result.success();
    }

    @Operation(summary = "用户数据统计", description = "获取用户的数据统计信息")
    @GetMapping("/stats")
    public Result<Object> getStats() {
        Long userId = SecurityContextUtil.getCurrentUserId();
        if (userId == null) {
            return Result.unauthorized("未登录");
        }
        // TODO: 实现用户数据统计
        return Result.success();
    }
}

